import service from '@/utils/request'
// import { createService } from '@/utils/request'
import { AxiosResponse } from 'axios'
import qs from 'qs'
import {Ref, UnwrapRef} from "vue";
import {reqRegisterStudent} from "@/api/student/type";

enum API {
    selectCourseURL = '/teach-system/course/list-select/{grade}/{majorId}',
    chooseCourseURL = '/teach-system/choose-course/stu-course/{courseId}',
    checkClassTableURL = '/teach-system/class-table/stu-check-table/{weekNum}',
    myCourseURL = '/teach-system/student/getStudentById/{id}',
    cancelMyCourseURL = '/teach-system/choose-course/stu-un-choose/{id}',
    getMyScoreURL = '/teach-system/choose-course/get-my-score/{id}',
    modifyMyPasswordURL = '/teach-system/student/modify-password/{newPassword}',
    stuRegisterURL = '/teach-system/student/register'
}

//学生获取已选课程
export const getMyCourse = (id:number) => {
    return service.teachService.get<any,AxiosResponse<any>>(
        API.myCourseURL.replace('{id}',id)
    )
}

//学生查询选课
export const searchCourse = (grade: number, majorId: number) => {
    // let url = API.chooseCourseURL.replace('{grade}',grade).replace('{marjorId}',majorId)
    // url = url.replace('{marjorId}',majorId)
    // console.log(url)
    // return service.teachService.get<any,AxiosResponse>(
    //     API.chooseCourseURL.replace('{grade}',grade).replace('{marjorId}',majorId)
    // )
    // return service.teachService.get<any, AxiosResponse>(url);
    const url = `/teach-system/course/list-select/${grade}/${majorId}`;
    return service.teachService.get<any, AxiosResponse>(url);
}

//学生选课
export const chooseCourse = (courseId:number) => {
    return service.teachService.get<any,AxiosResponse<any>>(
        API.chooseCourseURL.replace('{courseId}',courseId)
    )
}

//学生查看自己的每周课表
export const checkMyClassTable = (weekNum:number) => {
    return service.teachService.get<any,AxiosResponse<any>>(
        API.checkClassTableURL.replace('{weekNum}',weekNum)
    )
}

//学生退课
export const cancelMyCourse = (id:number) => {
    return service.teachService.delete<any,AxiosResponse<any>>(
        API.cancelMyCourseURL.replace('{id}',id)
    )
}

//学生查看自己的某科成绩
export const getMyScore = (id:number) => {
    return service.teachService.get<any,AxiosResponse<any>>(
        API.getMyScoreURL.replace('{id}',id)
    )
}

//学生修改密码
export const modifyMyPassword = (newPassword:string) => {
    return service.teachService.get<any,AxiosResponse<any>>(
        API.modifyMyPasswordURL.replace('{newPassword}',newPassword)
    )
}

//学生注册
export const stuRegister = (data: reqRegisterStudent) => {
    return service.teachService.post<any,AxiosResponse<any>>(
        API.stuRegisterURL,
        data
    )
}
